package com.first.agent.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.first.agent.common.R;
import com.first.agent.pojo.Keyword;
import com.first.agent.service.CustomerService;
import com.first.agent.service.impl.CustomerServiceImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created with IntelliJ IDEA.
 * User: lxm
 * Date: 2022/11/17 16:25
 * Description:
 * Version: V1.0
 */
@WebServlet("/customer/addKeyWords")
public class AddKeyWordsServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取前端页面值
        String customer_name = req.getParameter("customer_name");
        String kw_name = req.getParameter("kw_name");
        String service_type = req.getParameter("service_type");
        String application_period = req.getParameter("application_period");
        String kw_price = req.getParameter("kw_price");
        //放入实体类
        Keyword kw=new Keyword();
        kw.setCustomer_name(customer_name);
        kw.setKw_name(kw_name);
        kw.setService_type(service_type);
        kw.setApplication_period(Integer.parseInt(kw_price.trim()));
        kw.setKw_price(Integer.parseInt(kw_price));
        //调用service提交申请
        CustomerService csi=new CustomerServiceImp();
        R r = csi.addKeyWords(kw);
        System.out.println(r.getMsg());
        //响应
        resp.setContentType("application/json;charset=utf-8");
        PrintWriter writer = resp.getWriter();
        writer.write(JSONObject.toJSONString(r));
        writer.flush();
        writer.close();
    }
}
